/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

/* eslint-disable import/no-extraneous-dependencies */
import React, { Component } from 'react';
import ConfirmModal from '@/components/_pages/Allocation/components/GpAuthPrompt/ConfirmModal';
import { connect } from 'dva';

/**
 * 共配页面，拦截刷新
 *  */
@connect(({ loading, user, setting, router }) => ({
  currentUser: user.currentUser || {},
  loading: loading.effects['info/getInfo'],
  location: router.location,
  ...setting,
}))
class GpAuthLayout extends Component {
  state = {
    visible: false,
  };

  componentDidMount() {
    const { loading, options, location, currentUser } = this.props;
    const { key } = options;
    const { disclaimer_status } = currentUser;
    const intercept =
      key == 'yz' && location.pathname.indexOf('Allocation') >= 0 && disclaimer_status == 0;
    if (intercept && !loading) {
      this.setState({
        visible: true,
      });
    }
  }

  onConfirm = () => {
    this.setState({
      visible: false,
    });
  };

  render() {
    const { visible } = this.state;
    const { location, children, options, currentUser = {} } = this.props;
    const { key } = options;
    const { disclaimer_status } = currentUser;

    const intercept =
      key == 'yz' && location.pathname.indexOf('Allocation') >= 0 && disclaimer_status == 0;

    return (
      <>
        {!intercept && children}
        <ConfirmModal
          onOk={this.onConfirm}
          onCancel={() => {
            this.setState({
              visible: false,
            });
          }}
          visible={visible}
        />
      </>
    );
  }
}

export default GpAuthLayout;
